package entity;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author futao
 * Created on 18-2-6-上午10:14.
 */
@Converter(autoApply=true)
public class User_Sex_Convert implements AttributeConverter<User_Sex, Integer> {
    public Integer convertToDatabaseColumn(User_Sex attribute) {
        switch (attribute) {
            case Unkonw: {
                return User_Sex.Unkonw.ordinal();
            }
            case Man: {
                return User_Sex.Man.ordinal();
            }
            case Woman: {
                return User_Sex.Woman.ordinal();
            }
            default: {
                return null;
            }
        }
    }

    public User_Sex convertToEntityAttribute(Integer dbData) {
        switch (dbData) {
            case 0: {
                return User_Sex.Unkonw;
            }
            case 1: {
                return User_Sex.Man;
            }
            case 2: {
                return User_Sex.Woman;
            }
            default: {
                return null;
            }
        }
    }
}
